package com.murfrosoft.airhockey.entities;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class CompPaddle extends Paddle {

	@Override
	public void move(int width,int height, float puckX, float puckY) {
		/* UPDATE COMPUTER PADDLE POSITION */
		/* NOTE: When updating paddle position, we must ALSO update it's velocity, since 
		 * this is used in puck collision algorithm!  We will override any default set 
		 * velocities here */

		/* Define X speed and Y speed constants */
		int xspeed = 5;
		int yspeed = 3;
		
		/* If we are left or right of puck, we want to try to stay behind it */
		if( (positionX < (puckX-10)) && (positionX < (width-radius)) ){
			positionX += xspeed;
			velocityX = xspeed;
		}
		else if( (positionX > (puckX+10)) && (positionX > (radius)) ){
			positionX -= xspeed;
			velocityX = -xspeed;
		}
		else{
			velocityX = 0;		// New anti-stutter technology! MCM
		}
		
		/* if puck is on our side of table, move toward it, otherwise, move backwards */
		if( puckY < height/2 ){
			// Puck on our side of table: try to stay behind it (to avoid puck getting stuck in paddle)
			if( (positionY < (puckY-10)) && (positionY < (height/2 - radius)) ){
				positionY += 3*yspeed;
				velocityY = 3*yspeed;
			}
			else{
				if( positionY > 1.1f*radius ){
					positionY -= 2*yspeed;
					velocityY = -2*yspeed;
				}
			}
		}
		else{
			if( positionY > 1.1f*radius ){
				positionY -= 4*yspeed;
				velocityY = -4*yspeed;
			}
		}

		
	}

	@Override
	public void draw(Canvas canvas) {
		/* DRAW COMPUTER PADDLE */
		Paint paddle_color3 = new Paint();
		paddle_color3.setColor(Color.rgb(0, 0, 255));
		Paint paddle_color4 = new Paint();
		paddle_color4.setColor(Color.rgb(100, 100, 255));
		paddle_color4.setAntiAlias(true);
		paddle_color3.setAntiAlias(true);
	
		canvas.drawCircle(positionX,positionY, radius, paddle_color3);
		canvas.drawCircle(positionX,positionY, radius/2, paddle_color4);
		//canvas.drawBitmap(bitmap, positionX-radius, positionY-radius, paddle_color4);
		
	}



}
